
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import lejos.pc.comm.NXTCommLogListener;
import lejos.pc.comm.NXTConnector;

/**

 * 
 *
 * 
 * @author Luis C. Velasquez based on ideas of Lawrie Griffiths
 *
 */
public class BTSend {	
	public static void main(String[] args) {
		//enviar enviar = new enviar();
		enviar.comunicacion(4);
		
		
		//enviar.comunicacion(0);
		//enviar.comunicacion(1);
		//enviar.cerrarComunicacion();
		
		
		/**
		NXTConnector conn = new NXTConnector();
	
		conn.addLogListener(new NXTCommLogListener(){

			public void logEvent(String message) {
				System.out.println("BTSend Log.listener: "+message);
				
			}

			public void logEvent(Throwable throwable) {
				System.out.println("BTSend Log.listener - stack trace: ");
				 throwable.printStackTrace();
				
			}
			
		} 
		);
		// Conectamos a NXT con ptrotocolo bluetooth
		boolean connected = conn.connectTo("btspp://");
	
		
		if (!connected) {
			System.err.println("Failed to connect to any NXT");
			System.exit(1);
		}
		
		DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
		DataInputStream dis = new DataInputStream(conn.getInputStream());
		/*try {
			System.out.println("Sending " + (1));
			dos.writeInt((1));
			dos.flush();			
			
		} catch (IOException ioe) {
			System.out.println("IO Exception writing bytes:");
			System.out.println(ioe.getMessage());
			
		}*/	
		/**
		//Descomentar para probar comunicaciones
		for(int i=0;i<1;i++) {
			try {
				System.out.println("Sending " + (1));
				dos.writeInt((2));
				dos.flush();			
				
			} catch (IOException ioe) {
				System.out.println("IO Exception writing bytes:");
				System.out.println(ioe.getMessage());
				break;
			}
			
			/*try {
				
				System.out.println("Received " + dis.readInt());
			} catch (IOException ioe) {
				System.out.println("IO Exception reading bytes:");
				System.out.println(ioe.getMessage());
				break;
			}*/
		/**
		}
		
		try {
			dis.close();
			dos.close();
			conn.close();
		} catch (IOException ioe) {
			System.out.println("IOException closing connection:");
			System.out.println(ioe.getMessage());
		}
	}
	*/
	}
}
